package com.demo.springmvc.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author liangliang
 * <p>异常处理类</>
 */
@ControllerAdvice
public class HandleException {

    @ExceptionHandler(value = {ArithmeticException.class})
    public ModelAndView handleException(Exception ex) {
        System.out.println("》》出异常了》》");
        ModelAndView mv = new ModelAndView();
        mv.setViewName("error");
        mv.addObject("exception", ex.getMessage());
        return mv;
    }

}
